

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.dataset.engine.datasets_audio &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
        <script src="../../../../_static/jquery.js"></script>
        <script src="../../../../_static/underscore.js"></script>
        <script src="../../../../_static/doctools.js"></script>
        <script src="../../../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../api_python/mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../../index.html">Module code</a> &raquo;</li>
        
      <li>mindspore.dataset.engine.datasets_audio</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for mindspore.dataset.engine.datasets_audio</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright 2019-2022 Huawei Technologies Co., Ltd</span>
<span class="c1">#</span>
<span class="c1"># Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1"># you may not use this file except in compliance with the License.</span>
<span class="c1"># You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1"># http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1"># Unless required by applicable law or agreed to in writing, software</span>
<span class="c1"># distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1"># See the License for the specific language governing permissions and</span>
<span class="c1"># limitations under the License.</span>
<span class="c1"># ==============================================================================</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This file contains specific audio dataset loading classes. You can easily use</span>
<span class="sd">these classes to load the prepared dataset. For example:</span>
<span class="sd">    LJSpeechDataset: which is lj speech dataset.</span>
<span class="sd">    YesNoDataset: which is yes or no dataset.</span>
<span class="sd">    SpeechCommandsDataset: which is speech commands dataset.</span>
<span class="sd">    TedliumDataset: which is tedlium dataset.</span>
<span class="sd">    ...</span>
<span class="sd">After declaring the dataset object, you can further apply dataset operations</span>
<span class="sd">(e.g. filter, skip, concat, map, batch) on it.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">mindspore._c_dataengine</span> <span class="k">as</span> <span class="nn">cde</span>

<span class="kn">from</span> <span class="nn">.datasets</span> <span class="kn">import</span> <span class="n">AudioBaseDataset</span><span class="p">,</span> <span class="n">MappableDataset</span>
<span class="kn">from</span> <span class="nn">.validators</span> <span class="kn">import</span> <span class="n">check_lj_speech_dataset</span><span class="p">,</span> <span class="n">check_yes_no_dataset</span><span class="p">,</span> <span class="n">check_speech_commands_dataset</span><span class="p">,</span> \
    <span class="n">check_tedlium_dataset</span>

<span class="kn">from</span> <span class="nn">..core.validator_helpers</span> <span class="kn">import</span> <span class="n">replace_none</span>


<div class="viewcode-block" id="LJSpeechDataset"><a class="viewcode-back" href="../../../../api_python/dataset/mindspore.dataset.LJSpeechDataset.html#mindspore.dataset.LJSpeechDataset">[docs]</a><span class="k">class</span> <span class="nc">LJSpeechDataset</span><span class="p">(</span><span class="n">MappableDataset</span><span class="p">,</span> <span class="n">AudioBaseDataset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A source dataset that reads and parses LJSpeech dataset.</span>

<span class="sd">    The generated dataset has four columns :py:obj:`[waveform, sample_rate, transcription, normalized_transcript]`.</span>
<span class="sd">    The tensor of column :py:obj:`waveform` is a tensor of the float32 type.</span>
<span class="sd">    The tensor of column :py:obj:`sample_rate` is a scalar of the int32 type.</span>
<span class="sd">    The tensor of column :py:obj:`transcription` is a scalar of the string type.</span>
<span class="sd">    The tensor of column :py:obj:`normalized_transcript` is a scalar of the string type.</span>

<span class="sd">    Args:</span>
<span class="sd">        dataset_dir (str): Path to the root directory that contains the dataset.</span>
<span class="sd">        num_samples (int, optional): The number of audios to be included in the dataset</span>
<span class="sd">            (default=None, all audios).</span>
<span class="sd">        num_parallel_workers (int, optional): Number of workers to read the data</span>
<span class="sd">            (default=None, number set in the config).</span>
<span class="sd">        shuffle (bool, optional): Whether to perform shuffle on the dataset (default=None, expected</span>
<span class="sd">            order behavior shown in the table).</span>
<span class="sd">        sampler (Sampler, optional): Object used to choose samples from the</span>
<span class="sd">            dataset (default=None, expected order behavior shown in the table).</span>
<span class="sd">        num_shards (int, optional): Number of shards that the dataset will be divided</span>
<span class="sd">            into (default=None). When this argument is specified, `num_samples` reflects</span>
<span class="sd">            the maximum sample number of per shard.</span>
<span class="sd">        shard_id (int, optional): The shard ID within num_shards (default=None). This</span>
<span class="sd">            argument can only be specified when num_shards is also specified.</span>
<span class="sd">        cache (DatasetCache, optional): Use tensor caching service to speed up dataset processing.</span>
<span class="sd">            (default=None, which means no cache is used).</span>

<span class="sd">    Raises:</span>
<span class="sd">        RuntimeError: If dataset_dir does not contain data files.</span>
<span class="sd">        RuntimeError: If num_parallel_workers exceeds the max thread numbers.</span>
<span class="sd">        RuntimeError: If sampler and shuffle are specified at the same time.</span>
<span class="sd">        RuntimeError: If sampler and sharding are specified at the same time.</span>
<span class="sd">        RuntimeError: If num_shards is specified but shard_id is None.</span>
<span class="sd">        RuntimeError: If shard_id is specified but num_shards is None.</span>
<span class="sd">        ValueError: If shard_id is invalid (&lt; 0 or &gt;= num_shards).</span>

<span class="sd">    Note:</span>
<span class="sd">        - This dataset can take in a `sampler`. `sampler` and `shuffle` are mutually exclusive.</span>
<span class="sd">          The table below shows what input arguments are allowed and their expected behavior.</span>

<span class="sd">    .. list-table:: Expected Order Behavior of Using `sampler` and `shuffle`</span>
<span class="sd">       :widths: 25 25 50</span>
<span class="sd">       :header-rows: 1</span>

<span class="sd">       * - Parameter `sampler`</span>
<span class="sd">         - Parameter `shuffle`</span>
<span class="sd">         - Expected Order Behavior</span>
<span class="sd">       * - None</span>
<span class="sd">         - None</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - True</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - False</span>
<span class="sd">         - sequential order</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - None</span>
<span class="sd">         - order defined by sampler</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - True</span>
<span class="sd">         - not allowed</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - False</span>
<span class="sd">         - not allowed</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; lj_speech_dataset_dir = &quot;/path/to/lj_speech_dataset_directory&quot;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # 1) Get all samples from LJSPEECH dataset in sequence</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.LJSpeechDataset(dataset_dir=lj_speech_dataset_dir, shuffle=False)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # 2) Randomly select 350 samples from LJSPEECH dataset</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.LJSpeechDataset(dataset_dir=lj_speech_dataset_dir, num_samples=350, shuffle=True)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # 3) Get samples from LJSPEECH dataset for shard 0 in a 2-way distributed training</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.LJSpeechDataset(dataset_dir=lj_speech_dataset_dir, num_shards=2, shard_id=0)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # In LJSPEECH dataset, each dictionary has keys &quot;waveform&quot;, &quot;sample_rate&quot;, &quot;transcription&quot;</span>
<span class="sd">        &gt;&gt;&gt; # and &quot;normalized_transcript&quot;</span>

<span class="sd">    About LJSPEECH dataset:</span>

<span class="sd">    This is a public domain speech dataset consisting of 13,100 short audio clips of a single speaker</span>
<span class="sd">    reading passages from 7 non-fiction books. A transcription is provided for each clip.</span>
<span class="sd">    Clips vary in length from 1 to 10 seconds and have a total length of approximately 24 hours.</span>

<span class="sd">    The texts were published between 1884 and 1964, and are in the public domain.</span>
<span class="sd">    The audio was recorded in 2016-17 by the LibriVox project and is also in the public domain.</span>

<span class="sd">    Here is the original LJSPEECH dataset structure.</span>
<span class="sd">    You can unzip the dataset files into the following directory structure and read by MindSpore&#39;s API.</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        .</span>
<span class="sd">        └── LJSpeech-1.1</span>
<span class="sd">            ├── README</span>
<span class="sd">            ├── metadata.csv</span>
<span class="sd">            └── wavs</span>
<span class="sd">                ├── LJ001-0001.wav</span>
<span class="sd">                ├── LJ001-0002.wav</span>
<span class="sd">                ├── LJ001-0003.wav</span>
<span class="sd">                ├── LJ001-0004.wav</span>
<span class="sd">                ├── LJ001-0005.wav</span>
<span class="sd">                ├── LJ001-0006.wav</span>
<span class="sd">                ├── LJ001-0007.wav</span>
<span class="sd">                ├── LJ001-0008.wav</span>
<span class="sd">                ...</span>
<span class="sd">                ├── LJ050-0277.wav</span>
<span class="sd">                └── LJ050-0278.wav</span>

<span class="sd">    Citation:</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        @misc{lj_speech17,</span>
<span class="sd">        author       = {Keith Ito and Linda Johnson},</span>
<span class="sd">        title        = {The LJ Speech Dataset},</span>
<span class="sd">        howpublished = {url{https://keithito.com/LJ-Speech-Dataset}},</span>
<span class="sd">        year         = 2017</span>
<span class="sd">        }</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@check_lj_speech_dataset</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataset_dir</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_parallel_workers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">sampler</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">num_parallel_workers</span><span class="o">=</span><span class="n">num_parallel_workers</span><span class="p">,</span> <span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="n">num_samples</span><span class="p">,</span>
                         <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="n">num_shards</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="n">shard_id</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="n">cache</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span> <span class="o">=</span> <span class="n">dataset_dir</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">children</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cde</span><span class="o">.</span><span class="n">LJSpeechNode</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampler</span><span class="p">)</span></div>


<div class="viewcode-block" id="SpeechCommandsDataset"><a class="viewcode-back" href="../../../../api_python/dataset/mindspore.dataset.SpeechCommandsDataset.html#mindspore.dataset.SpeechCommandsDataset">[docs]</a><span class="k">class</span> <span class="nc">SpeechCommandsDataset</span><span class="p">(</span><span class="n">MappableDataset</span><span class="p">,</span> <span class="n">AudioBaseDataset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A source dataset that reads and parses the SpeechCommands dataset.</span>

<span class="sd">    The generated dataset has five columns :py:obj:`[waveform, sample_rate, label, speaker_id, utterance_number]`.</span>
<span class="sd">    The tensor of column :py:obj:`waveform` is a vector of the float32 type.</span>
<span class="sd">    The tensor of column :py:obj:`sample_rate` is a scalar of the int32 type.</span>
<span class="sd">    The tensor of column :py:obj:`label` is a scalar of the string type.</span>
<span class="sd">    The tensor of column :py:obj:`speaker_id` is a scalar of the string type.</span>
<span class="sd">    The tensor of column :py:obj:`utterance_number` is a scalar of the int32 type.</span>

<span class="sd">    Args:</span>
<span class="sd">        dataset_dir (str): Path to the root directory that contains the dataset.</span>
<span class="sd">        usage (str, optional): Usage of this dataset, can be `train`, `test`, `valid` or `all`. `train`</span>
<span class="sd">            will read from 84,843 samples, `test` will read from 11,005 samples, `valid` will read from 9,981</span>
<span class="sd">            test samples and `all` will read from all 105,829 samples (default=None, will read all samples).</span>
<span class="sd">        num_samples (int, optional): The number of samples to be included in the dataset</span>
<span class="sd">            (default=None, will read all samples).</span>
<span class="sd">        num_parallel_workers (int, optional): Number of workers to read the data</span>
<span class="sd">            (default=None, will use value set in the config).</span>
<span class="sd">        shuffle (bool, optional): Whether or not to perform shuffle on the dataset</span>
<span class="sd">            (default=None, expected order behavior shown in the table).</span>
<span class="sd">        sampler (Sampler, optional): Object used to choose samples from the dataset</span>
<span class="sd">            (default=None, expected order behavior shown in the table).</span>
<span class="sd">        num_shards (int, optional): Number of shards that the dataset will be divided into (default=None).</span>
<span class="sd">            When this argument is specified, `num_samples` reflects the maximum sample number of per shard.</span>
<span class="sd">        shard_id (int, optional): The shard ID within `num_shards` (default=None). This argument can only be specified</span>
<span class="sd">            when `num_shards` is also specified.</span>
<span class="sd">        cache (DatasetCache, optional): Use tensor caching service to speed up dataset processing</span>
<span class="sd">            (default=None, which means no cache is used).</span>

<span class="sd">    Raises:</span>
<span class="sd">        RuntimeError: If dataset_dir does not contain data files.</span>
<span class="sd">        RuntimeError: If num_parallel_workers exceeds the max thread numbers.</span>
<span class="sd">        RuntimeError: If sampler and shuffle are specified at the same time.</span>
<span class="sd">        RuntimeError: If sampler and sharding are specified at the same time.</span>
<span class="sd">        RuntimeError: If num_shards is specified but shard_id is None.</span>
<span class="sd">        RuntimeError: If shard_id is specified but num_shards is None.</span>
<span class="sd">        ValueError: If shard_id is invalid (&lt; 0 or &gt;= num_shards).</span>

<span class="sd">    Note:</span>
<span class="sd">        - This dataset can take in a `sampler`. `sampler` and `shuffle` are mutually exclusive.</span>
<span class="sd">          The table below shows what input arguments are allowed and their expected behavior.</span>

<span class="sd">    .. list-table:: Expected Order Behavior of Using `sampler` and `shuffle`</span>
<span class="sd">       :widths: 25 25 50</span>
<span class="sd">       :header-rows: 1</span>

<span class="sd">       * - Parameter `sampler`</span>
<span class="sd">         - Parameter `shuffle`</span>
<span class="sd">         - Expected Order Behavior</span>
<span class="sd">       * - None</span>
<span class="sd">         - None</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - True</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - False</span>
<span class="sd">         - sequential order</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - None</span>
<span class="sd">         - order defined by sampler</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - True</span>
<span class="sd">         - not allowed</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - False</span>
<span class="sd">         - not allowed</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; speech_commands_dataset_dir = &quot;/path/to/speech_commands_dataset_directory&quot;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # Read 3 samples from SpeechCommands dataset</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.SpeechCommandsDataset(dataset_dir=speech_commands_dataset_dir, num_samples=3)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # Note: In SpeechCommands dataset, each dictionary has keys &quot;waveform&quot;, &quot;sample_rate&quot;, &quot;label&quot;,</span>
<span class="sd">        &gt;&gt;&gt; # &quot;speaker_id&quot; and &quot;utterance_number&quot;.</span>

<span class="sd">    About SpeechCommands dataset:</span>

<span class="sd">    The SpeechCommands is database for limited_vocabulary speech recognition, containing 105,829 audio samples of</span>
<span class="sd">    &#39;.wav&#39; format.</span>

<span class="sd">    Here is the original SpeechCommands dataset structure.</span>
<span class="sd">    You can unzip the dataset files into this directory structure and read by MindSpore&#39;s API.</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        .</span>
<span class="sd">        └── speech_commands_dataset_dir</span>
<span class="sd">             ├── cat</span>
<span class="sd">                  ├── b433eff_nohash_0.wav</span>
<span class="sd">                  ├── 5a33edf_nohash_1.wav</span>
<span class="sd">                  └──....</span>
<span class="sd">             ├── dog</span>
<span class="sd">                  ├── b433w2w_nohash_0.wav</span>
<span class="sd">                  └──....</span>
<span class="sd">             ├── four</span>
<span class="sd">             └── ....</span>

<span class="sd">    Citation:</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        @article{2018Speech,</span>
<span class="sd">        title={Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition},</span>
<span class="sd">        author={Warden, P.},</span>
<span class="sd">        year={2018}</span>
<span class="sd">        }</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@check_speech_commands_dataset</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataset_dir</span><span class="p">,</span> <span class="n">usage</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_parallel_workers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">sampler</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">num_parallel_workers</span><span class="o">=</span><span class="n">num_parallel_workers</span><span class="p">,</span> <span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="n">num_samples</span><span class="p">,</span>
                         <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="n">num_shards</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="n">shard_id</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="n">cache</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span> <span class="o">=</span> <span class="n">dataset_dir</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">usage</span> <span class="o">=</span> <span class="n">replace_none</span><span class="p">(</span><span class="n">usage</span><span class="p">,</span> <span class="s2">&quot;all&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">children</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cde</span><span class="o">.</span><span class="n">SpeechCommandsNode</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">usage</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampler</span><span class="p">)</span></div>


<div class="viewcode-block" id="TedliumDataset"><a class="viewcode-back" href="../../../../api_python/dataset/mindspore.dataset.TedliumDataset.html#mindspore.dataset.TedliumDataset">[docs]</a><span class="k">class</span> <span class="nc">TedliumDataset</span><span class="p">(</span><span class="n">MappableDataset</span><span class="p">,</span> <span class="n">AudioBaseDataset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A source dataset that reads and parses Tedlium dataset.</span>
<span class="sd">    The columns of generated dataset depend on the source SPH files and the corresponding STM files.</span>

<span class="sd">    The generated dataset has six columns :py:obj:`[waveform, sample_rate, transcript, talk_id, speaker_id,</span>
<span class="sd">    identifier]`.</span>

<span class="sd">    The tensor of column :py:obj:`waveform` is of the float32 type.</span>
<span class="sd">    The tensor of column :py:obj:`sample_rate` is a scalar of the int32 type.</span>
<span class="sd">    The tensor of column :py:obj:`transcript` is a scalar of the string type.</span>
<span class="sd">    The tensor of column :py:obj:`talk_id` is a scalar of the string type.</span>
<span class="sd">    The tensor of column :py:obj:`speaker_id` is a scalar of the string type.</span>
<span class="sd">    The tensor of column :py:obj:`identifier` is a scalar of the string type.</span>

<span class="sd">    Args:</span>
<span class="sd">        dataset_dir (str): Path to the root directory that contains the dataset.</span>
<span class="sd">        release (str): Release of the dataset, can be &quot;release1&quot;, &quot;release2&quot;, &quot;release3&quot;.</span>
<span class="sd">        usage (str, optional): Usage of this dataset.</span>
<span class="sd">            For release1 or release2, can be `train`, `test`, `dev` or `all`.</span>
<span class="sd">            `train` will read from train samples,</span>
<span class="sd">            `test` will read from test samples,</span>
<span class="sd">            `dev` will read from dev samples,</span>
<span class="sd">            `all` will read from all samples.</span>
<span class="sd">            For release3, can only be &quot;all&quot;, it will read from data samples (default=None, all samples).</span>
<span class="sd">        extensions (str): Extensions of the SPH files, only &#39;.sph&#39; is valid.</span>
<span class="sd">            (default=None, &quot;.sph&quot;).</span>
<span class="sd">        num_samples (int, optional): The number of audio samples to be included in the dataset</span>
<span class="sd">            (default=None, all samples).</span>
<span class="sd">        num_parallel_workers (int, optional): Number of workers to read the data</span>
<span class="sd">            (default=None, number set in the config).</span>
<span class="sd">        shuffle (bool, optional): Whether to perform shuffle on the dataset (default=None, expected</span>
<span class="sd">            order behavior shown in the table).</span>
<span class="sd">        sampler (Sampler, optional): Object used to choose samples from the</span>
<span class="sd">            dataset (default=None, expected order behavior shown in the table).</span>
<span class="sd">        num_shards (int, optional): Number of shards that the dataset will be divided</span>
<span class="sd">            into (default=None). When this argument is specified, `num_samples` reflects</span>
<span class="sd">            the maximum sample number of per shard.</span>
<span class="sd">        shard_id (int, optional): The shard ID within num_shards (default=None). This</span>
<span class="sd">            argument can only be specified when num_shards is also specified.</span>
<span class="sd">        cache (DatasetCache, optional): Use tensor caching service to speed up dataset processing.</span>
<span class="sd">            (default=None, which means no cache is used).</span>

<span class="sd">    Raises:</span>
<span class="sd">        RuntimeError: If dataset_dir does not contain stm files.</span>
<span class="sd">        RuntimeError: If num_parallel_workers exceeds the max thread numbers.</span>
<span class="sd">        RuntimeError: If sampler and shuffle are specified at the same time.</span>
<span class="sd">        RuntimeError: If sampler and sharding are specified at the same time.</span>
<span class="sd">        RuntimeError: If num_shards is specified but shard_id is None.</span>
<span class="sd">        RuntimeError: If shard_id is specified but num_shards is None.</span>
<span class="sd">        ValueError: If shard_id is invalid (&lt; 0 or &gt;= num_shards).</span>

<span class="sd">    Note:</span>
<span class="sd">        - This dataset can take in a `sampler`. `sampler` and `shuffle` are mutually exclusive.</span>
<span class="sd">          The table below shows what input arguments are allowed and their expected behavior.</span>

<span class="sd">    .. list-table:: Expected Order Behavior of Using `sampler` and `shuffle`</span>
<span class="sd">       :widths: 25 25 50</span>
<span class="sd">       :header-rows: 1</span>

<span class="sd">       * - Parameter `sampler`</span>
<span class="sd">         - Parameter `shuffle`</span>
<span class="sd">         - Expected Order Behavior</span>
<span class="sd">       * - None</span>
<span class="sd">         - None</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - True</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - False</span>
<span class="sd">         - sequential order</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - None</span>
<span class="sd">         - order defined by sampler</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - True</span>
<span class="sd">         - not allowed</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - False</span>
<span class="sd">         - not allowed</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; # 1) Get all train samples from TEDLIUM_release1 dataset in sequence.</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.TedliumDataset(dataset_dir=&quot;/path/to/tedlium1_dataset_directory&quot;,</span>
<span class="sd">        ...                             release=&quot;release1&quot;, shuffle=False)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # 2) Randomly select 10 samples from TEDLIUM_release2 dataset.</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.TedliumDataset(dataset_dir=&quot;/path/to/tedlium2_dataset_directory&quot;,</span>
<span class="sd">        ...                             release=&quot;release2&quot;, num_samples=10, shuffle=True)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # 3) Get samples from TEDLIUM_release-3 dataset for shard 0 in a 2-way distributed training.</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.TedliumDataset(dataset_dir=&quot;/path/to/tedlium3_dataset_directory&quot;,</span>
<span class="sd">        ...                             release=&quot;release3&quot;, num_shards=2, shard_id=0)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # In TEDLIUM dataset, each dictionary has keys : waveform, sample_rate, transcript, talk_id,</span>
<span class="sd">        &gt;&gt;&gt; # speaker_id and identifier.</span>

<span class="sd">    About TEDLIUM_release1 dataset:</span>

<span class="sd">    The TED-LIUM corpus is English-language TED talks, with transcriptions, sampled at 16kHz.</span>
<span class="sd">    It contains about 118 hours of speech.</span>

<span class="sd">    About TEDLIUM_release2 dataset:</span>

<span class="sd">    This is the TED-LIUM corpus release 2, licensed under Creative Commons BY-NC-ND 3.0. All talks and text are</span>
<span class="sd">    property of TED Conferences LLC. The TED-LIUM corpus was made from audio talks and their transcriptions available</span>
<span class="sd">    on the TED website. We have prepared and filtered these data in order to train acoustic models to participate to</span>
<span class="sd">    the International Workshop on Spoken Language Translation 2011 (the LIUM English/French SLT system reached the</span>
<span class="sd">    first rank in the SLT task).</span>

<span class="sd">    About TEDLIUM_release-3 dataset:</span>

<span class="sd">    This is the TED-LIUM corpus release 3, licensed under Creative Commons BY-NC-ND 3.0. All talks and text are</span>
<span class="sd">    property of TED Conferences LLC. This new TED-LIUM release was made through a collaboration between the Ubiqus</span>
<span class="sd">    company and the LIUM (University of Le Mans, France).</span>

<span class="sd">    You can unzip the dataset files into the following directory structure and read by MindSpore&#39;s API.</span>

<span class="sd">    The structure of TEDLIUM release2 is the same as TEDLIUM release1, only the data is different.</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        .</span>
<span class="sd">        └──TEDLIUM_release1</span>
<span class="sd">            └── dev</span>
<span class="sd">                ├── sph</span>
<span class="sd">                    ├── AlGore_2009.sph</span>
<span class="sd">                    ├── BarrySchwartz_2005G.sph</span>
<span class="sd">                ├── stm</span>
<span class="sd">                    ├── AlGore_2009.stm</span>
<span class="sd">                    ├── BarrySchwartz_2005G.stm</span>
<span class="sd">            └── test</span>
<span class="sd">                ├── sph</span>
<span class="sd">                    ├── AimeeMullins_2009P.sph</span>
<span class="sd">                    ├── BillGates_2010.sph</span>
<span class="sd">                ├── stm</span>
<span class="sd">                    ├── AimeeMullins_2009P.stm</span>
<span class="sd">                    ├── BillGates_2010.stm</span>
<span class="sd">            └── train</span>
<span class="sd">                ├── sph</span>
<span class="sd">                    ├── AaronHuey_2010X.sph</span>
<span class="sd">                    ├── AdamGrosser_2007.sph</span>
<span class="sd">                ├── stm</span>
<span class="sd">                    ├── AaronHuey_2010X.stm</span>
<span class="sd">                    ├── AdamGrosser_2007.stm</span>
<span class="sd">            └── readme</span>
<span class="sd">            └── TEDLIUM.150k.dic</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        .</span>
<span class="sd">        └──TEDLIUM_release-3</span>
<span class="sd">            └── data</span>
<span class="sd">                ├── ctl</span>
<span class="sd">                ├── sph</span>
<span class="sd">                    ├── 911Mothers_2010W.sph</span>
<span class="sd">                    ├── AalaElKhani.sph</span>
<span class="sd">                ├── stm</span>
<span class="sd">                    ├── 911Mothers_2010W.stm</span>
<span class="sd">                    ├── AalaElKhani.stm</span>
<span class="sd">            └── doc</span>
<span class="sd">            └── legacy</span>
<span class="sd">            └── LM</span>
<span class="sd">            └── speaker-adaptation</span>
<span class="sd">            └── readme</span>
<span class="sd">            └── TEDLIUM.150k.dic</span>

<span class="sd">    Citation:</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        @article{</span>
<span class="sd">          title={TED-LIUM: an automatic speech recognition dedicated corpus},</span>
<span class="sd">          author={A. Rousseau, P. Deléglise, Y. Estève},</span>
<span class="sd">          journal={Proceedings of the Eighth International Conference on Language Resources and Evaluation (LREC&#39;12)},</span>
<span class="sd">          year={May 2012},</span>
<span class="sd">          biburl={https://www.openslr.org/7/}</span>
<span class="sd">        }</span>

<span class="sd">        @article{</span>
<span class="sd">          title={Enhancing the TED-LIUM Corpus with Selected Data for Language Modeling and More TED Talks},</span>
<span class="sd">          author={A. Rousseau, P. Deléglise, and Y. Estève},</span>
<span class="sd">          journal={Proceedings of the Eighth International Conference on Language Resources and Evaluation (LREC&#39;12)},</span>
<span class="sd">          year={May 2014},</span>
<span class="sd">          biburl={https://www.openslr.org/19/}</span>
<span class="sd">        }</span>

<span class="sd">        @article{</span>
<span class="sd">          title={TED-LIUM 3: twice as much data and corpus repartition for experiments on speaker adaptation},</span>
<span class="sd">          author={François Hernandez, Vincent Nguyen, Sahar Ghannay, Natalia Tomashenko, and Yannick Estève},</span>
<span class="sd">          journal={the 20th International Conference on Speech and Computer (SPECOM 2018)},</span>
<span class="sd">          year={September 2018},</span>
<span class="sd">          biburl={https://www.openslr.org/51/}</span>
<span class="sd">        }</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@check_tedlium_dataset</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataset_dir</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">usage</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">extensions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">num_parallel_workers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">sampler</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">shard_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">num_parallel_workers</span><span class="o">=</span><span class="n">num_parallel_workers</span><span class="p">,</span> <span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="n">num_samples</span><span class="p">,</span>
                         <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="n">num_shards</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="n">shard_id</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="n">cache</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span> <span class="o">=</span> <span class="n">dataset_dir</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extensions</span> <span class="o">=</span> <span class="n">replace_none</span><span class="p">(</span><span class="n">extensions</span><span class="p">,</span> <span class="s2">&quot;.sph&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">release</span> <span class="o">=</span> <span class="n">release</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">usage</span> <span class="o">=</span> <span class="n">replace_none</span><span class="p">(</span><span class="n">usage</span><span class="p">,</span> <span class="s2">&quot;all&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">children</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cde</span><span class="o">.</span><span class="n">TedliumNode</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">release</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">usage</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">extensions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampler</span><span class="p">)</span></div>


<div class="viewcode-block" id="YesNoDataset"><a class="viewcode-back" href="../../../../api_python/dataset/mindspore.dataset.YesNoDataset.html#mindspore.dataset.YesNoDataset">[docs]</a><span class="k">class</span> <span class="nc">YesNoDataset</span><span class="p">(</span><span class="n">MappableDataset</span><span class="p">,</span> <span class="n">AudioBaseDataset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A source dataset that reads and parses the YesNo dataset.</span>

<span class="sd">    The generated dataset has three columns :py:obj:`[waveform, sample_rate, labels]`.</span>
<span class="sd">    The tensor of column :py:obj:`waveform` is a vector of the float32 type.</span>
<span class="sd">    The tensor of column :py:obj:`sample_rate` is a scalar of the int32 type.</span>
<span class="sd">    The tensor of column :py:obj:`labels` is a scalar of the int32 type.</span>

<span class="sd">    Args:</span>
<span class="sd">        dataset_dir (str): Path to the root directory that contains the dataset.</span>
<span class="sd">        num_samples (int, optional): The number of images to be included in the dataset</span>
<span class="sd">            (default=None, will read all images).</span>
<span class="sd">        num_parallel_workers (int, optional): Number of workers to read the data</span>
<span class="sd">            (default=None, will use value set in the config).</span>
<span class="sd">        shuffle (bool, optional): Whether or not to perform shuffle on the dataset</span>
<span class="sd">            (default=None, expected order behavior shown in the table).</span>
<span class="sd">        sampler (Sampler, optional): Object used to choose samples from the</span>
<span class="sd">            dataset (default=None, expected order behavior shown in the table).</span>
<span class="sd">        num_shards (int, optional): Number of shards that the dataset will be divided into (default=None).</span>
<span class="sd">            When this argument is specified, `num_samples` reflects the maximum sample number of per shard.</span>
<span class="sd">        shard_id (int, optional): The shard ID within `num_shards` (default=None). This argument can only</span>
<span class="sd">            be specified when `num_shards` is also specified.</span>
<span class="sd">        cache (DatasetCache, optional): Use tensor caching service to speed up dataset processing</span>
<span class="sd">            (default=None, which means no cache is used).</span>

<span class="sd">    Raises:</span>
<span class="sd">        RuntimeError: If dataset_dir does not contain data files.</span>
<span class="sd">        RuntimeError: If num_parallel_workers exceeds the max thread numbers.</span>
<span class="sd">        RuntimeError: If sampler and shuffle are specified at the same time.</span>
<span class="sd">        RuntimeError: If sampler and sharding are specified at the same time.</span>
<span class="sd">        RuntimeError: If num_shards is specified but shard_id is None.</span>
<span class="sd">        RuntimeError: If shard_id is specified but num_shards is None.</span>
<span class="sd">        ValueError: If shard_id is invalid (&lt; 0 or &gt;= num_shards).</span>

<span class="sd">    Note:</span>
<span class="sd">        - This dataset can take in a `sampler`. `sampler` and `shuffle` are mutually exclusive.</span>
<span class="sd">          The table below shows what input arguments are allowed and their expected behavior.</span>

<span class="sd">    .. list-table:: Expected Order Behavior of Using `sampler` and `shuffle`</span>
<span class="sd">       :widths: 25 25 50</span>
<span class="sd">       :header-rows: 1</span>

<span class="sd">       * - Parameter `sampler`</span>
<span class="sd">         - Parameter `shuffle`</span>
<span class="sd">         - Expected Order Behavior</span>
<span class="sd">       * - None</span>
<span class="sd">         - None</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - True</span>
<span class="sd">         - random order</span>
<span class="sd">       * - None</span>
<span class="sd">         - False</span>
<span class="sd">         - sequential order</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - None</span>
<span class="sd">         - order defined by sampler</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - True</span>
<span class="sd">         - not allowed</span>
<span class="sd">       * - Sampler object</span>
<span class="sd">         - False</span>
<span class="sd">         - not allowed</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; yes_no_dataset_dir = &quot;/path/to/yes_no_dataset_directory&quot;</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # Read 3 samples from YesNo dataset</span>
<span class="sd">        &gt;&gt;&gt; dataset = ds.YesNoDataset(dataset_dir=yes_no_dataset_dir, num_samples=3)</span>
<span class="sd">        &gt;&gt;&gt;</span>
<span class="sd">        &gt;&gt;&gt; # Note: In YesNo dataset, each dictionary has keys &quot;waveform&quot;, &quot;sample_rate&quot;, &quot;label&quot;</span>

<span class="sd">    About YesNo dataset:</span>

<span class="sd">    Yesno is an audio dataset consisting of 60 recordings of one individual saying yes or no in Hebrew; each</span>
<span class="sd">    recording is eight words long. It was created for the Kaldi audio project by an author who wishes to</span>
<span class="sd">    remain anonymous.</span>

<span class="sd">    Here is the original YesNo dataset structure.</span>
<span class="sd">    You can unzip the dataset files into this directory structure and read by MindSpore&#39;s API.</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        .</span>
<span class="sd">        └── yes_no_dataset_dir</span>
<span class="sd">             ├── 1_1_0_0_1_1_0_0.wav</span>
<span class="sd">             ├── 1_0_0_0_1_1_0_0.wav</span>
<span class="sd">             ├── 1_1_0_0_1_1_0_0.wav</span>
<span class="sd">             └──....</span>

<span class="sd">    Citation:</span>

<span class="sd">    .. code-block::</span>

<span class="sd">        @NetworkResource{Kaldi_audio_project,</span>
<span class="sd">        author    = {anonymous},</span>
<span class="sd">        url       = &quot;http://wwww.openslr.org/1/&quot;</span>
<span class="sd">        }</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@check_yes_no_dataset</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataset_dir</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_parallel_workers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">sampler</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">num_parallel_workers</span><span class="o">=</span><span class="n">num_parallel_workers</span><span class="p">,</span> <span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="n">num_samples</span><span class="p">,</span>
                         <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">num_shards</span><span class="o">=</span><span class="n">num_shards</span><span class="p">,</span> <span class="n">shard_id</span><span class="o">=</span><span class="n">shard_id</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="n">cache</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span> <span class="o">=</span> <span class="n">dataset_dir</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">children</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cde</span><span class="o">.</span><span class="n">YesNoNode</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampler</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>